//
// Created by Zhangwj on 2023/9/26.
//

#include "ConstDefNode.h"

std::unique_ptr<ConstDefNode> ConstDefNode::ConstDefParser(Parser &parser) {
    //ConstDef → Ident { '[' ConstExp ']' } '=' ConstInitVal
    std::unique_ptr<ConstDefNode> constDefNode = std::make_unique<ConstDefNode>();
    constDefNode->Ident = IdentNode::IdentParser(parser);
    while (parser.getLexType(0) == LexType::LBRACK) {
        parser.next();
        constDefNode->ConstExps.push_back(ConstExpNode::ConstExpParser(parser));
        if (parser.getLexType(0) == LexType::RBRACK) {
            parser.next();
        }
    }
    if (parser.getLexType(0) == LexType::ASSIGN) {
        parser.next();
    }
    constDefNode->ConstInitVal = ConstInitValNode::ConstInitValParser(parser);
    return constDefNode;
}
